<%@language=vbscript%>
<%
	Session("FormName")=""
	Session("VanBan")=""
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">

<!--#include file="..\CheckSession.inc"-->
<!--#include file="..\jvGrid.inc"-->
<!--#include file="..\pageSelected.inc"-->
<!--#include file=..\getFormName.inc-->
<%
	'set Conn=server.CreateObject("ADODB.Connection")
	'Conn.Open Application("StrConn")
	bComm=Request("bComm")	
	Chon=request("chon")
	if Chon="all" then
		sTemp=""
	else
		' bg thphuc 20-02-03
		if Session("ClsFun").LayGiaTriQuyen(Session("Permision"),"F39",1)="1" or Session("IsAdmin") then
			sTemp=" and flownode.trangthaixl in (0,1) "
		else
			sTemp=" and DATEDIFF(day,flownode.hanxuly,GETDATE())<=0 and flownode.trangthaixl in (0,1) "
		end if
		' ed thphuc 20-02-03
	end if
	Select case bComm
		case "search"
			bTrichyeu=request("TxtTrichyeu")
			bTungay=Request("TxtTungay")
			bDenngay=Request("TxtDenNgay")
			if (bTungay<>"" and bDenNgay<>"") then
				sSQL="select distinct flownode.maworkflow,workflow.tenvuviec,workflow.nguoitao,workflow.ngaytao,workflow.tentepxuly from flownode inner join workflow on flownode.maworkflow=workflow.maworkflow where nguoixuly like '"& Session("bMaCB") &"'"
				sSQL=SSQL+" And Workflow.Tam<>1 And workflow.tenvuviec like '%"& Modistring(bTrichyeu) &"%'"
				sSQL=sSQL+" And ( workflow.Ngaytao Between '"& SaveDate(bTungay) &"' And '"& SaveDate(bDenngay) &"')"
				sSQL=sSQL+sTemp+" order by workflow.ngaytao DESC"
			else
				sSQL="select distinct flownode.maworkflow,workflow.tenvuviec,workflow.nguoitao,workflow.ngaytao,workflow.tentepxuly from flownode inner join workflow on flownode.maworkflow=workflow.maworkflow where nguoixuly like '"& Session("bMaCB") &"'"
				sSQL=SSQL+" And Workflow.Tam<>1 And workflow.tenvuviec like '%"& Modistring(bTrichyeu) &"%'"
				sSQL=sSQL+sTemp+" order by workflow.ngaytao DESC"
			end if
		Case else
			sSQL="select distinct flownode.maworkflow,workflow.tenvuviec,workflow.nguoitao,workflow.ngaytao,workflow.tentepxuly from flownode inner join workflow on flownode.maworkflow=workflow.maworkflow where Workflow.Tam<>1 And nguoixuly like '"& Session("bMaCB") &"'" + sTemp + " order by workflow.ngaytao DESC"
	end select	
	Set Rec=server.CreateObject("ADODB.recordset")
	Rec.CursorType=3
	Rec.CacheSize=5
	Dim nRecCount	' Number of records found
	Dim nPageCount	' Number of pages of records we have
	Dim nPage	' Current page number
	nPage=CLng(request("Page"))	
	if nPage="" then nPage=1
	Rec.Open sSQL,Conn
	if  rec.EOF and rec.BOF then
		nPageCount=0
	end if		
%>
<!--#include file="..\jvfunction.inc"-->
<script language=VBScript runat=server>
	' H&#224;m &#273;&#7883;nh d&#7841;ng l&#7841;i ng&#224;y M/D/Y-> D/M/Y
	Function FormatDate(vDate)
	   If Not IsNull(vDate) Then
	        vM = Right("0" & Month(vDate), 2)
	        vD = Right("0" & Day(vDate), 2)
	        vY = Right("19" & Year(vDate), 4)
	        FormatDate = vD & "/" & vM & "/" & vY
	   End If
	End Function
	Function ModiString(mess_s)
		message = Replace("" & mess_s,"'", "''")
		ModiString=message
	End function
	Function SaveDate(vDate)
		dim bvitri1
		dim bvitri2
	   vDate=trim(cstr(vDate))
	   bvitri1=instr(1,vDate,"/")
	   bMonth=left(vDate,bvitri1-1)
	   bvitri2=instr(bvitri1+1,vDate,"/")
	   Dim Temp
	   Temp=right(vDate,len(vDate)-bvitri1)
	   bDay=left(Temp,bvitri2-bvitri1-1)
	   bYear=right(vDate,len(vDate)-bvitri2)
       SaveDate=bDay+"/"+bMonth+"/"+bYear
	End Function
Function Paging(ByVal intPage, ByVal intPageCount, ByVal intRecordCount)
	Dim strQueryString
	Dim strScript
	Dim intStart
	Dim intEnd
	Dim strRet
	Dim i

	If intPage > intPageCount Then
		intPage = intPageCount
	ElseIf intPage < 1 Then 
		intPage = 1
	End If
	
	If intRecordCount = 0 Then
		'strRet = "No Records Found"
	ElseIf intPageCount = 1 Then
		'strRet = "End Of Hits"
	Else
		For i = 1 To Request.QueryString.Count
			If LCase(Request.QueryString.Key(i)) <> "page" Then
				strQueryString = strQueryString & "&" 
				strQueryString = strQueryString & Server.URLEncode(Request.QueryString.Key(i)) & "=" 
				strQueryString = strQueryString & Server.URLEncode(Request.QueryString.Item(i))
			End If
		Next

		For i = 1 To Request.Form.Count
			If LCase(Request.Form.Key(i)) <> "page" Then
				strQueryString = strQueryString & "&" 
				strQueryString = strQueryString & Server.URLEncode(Request.Form.Key(i)) & "=" 
				strQueryString = strQueryString & Server.URLEncode(Request.Form.Item(i))
			End If
		Next

		If Len(strQueryString) <> 0 Then
			strQueryString = "?" & Mid(strQueryString, 2) & "&"
		Else
			strQueryString = "?"
		End If

		strScript = Request.ServerVariables("SCRIPT_NAME") & strQueryString
	
		If intPage <= 10 Then
			intStart = 1
		Else
			If (intPage Mod 10) = 0 Then
				intStart = intPage - 9
			Else
				intStart = intPage - (intPage Mod 10) + 1
			End If
		End If

		intEnd = intStart + 9
		If intEnd > intPageCount Then intEnd = intPageCount
	
		'strRet = "Page " & intPage & " of " & intPageCount & ": "
	
		If intPage > 10 Then 
			strRet = strRet & "<a href=""" & strScript
			strRet = strRet & "page=" & intPage - 10 
			strRet = strRet & """><IMG border=0 SRC=../images/prev.gif></a> "
		End If
	
		For i = intStart To intEnd
			If i = intPage Then
				strRet = strRet & "<b><font color=A90A08>" & i & "</font></b> "
			Else
				strRet = strRet & "<a href=""" & strScript
				strRet = strRet & "page=" & i 
				strRet = strRet & """>" & i & "</a>"
				If i <> intEnd Then strRet = strRet & " "
			End If
		Next
	
		If intPage <> intPageCount and intPageCount > 10 Then
			strRet = strRet & " <a href=""" & strScript
			strRet = strRet & "page=" & intPage + 10 
			strRet = strRet & """><IMG border=0 SRC=../images/next.gif></a> "
		End If
	End If
	
	Paging = strRet
End Function
</script>	
<SCRIPT ID=clientEventHandlersJS LANGUAGE=javascript>
<!--
function ChangePage(){
	strURL=frm.page.value;
	window.frm.target="right";
	window.frm.action=strURL;
	window.frm.submit();
}

function CmdSearch_onclick() {
	if (frm.TxtTrichyeu.disabled){
		frm.CmdSearch.value="Tì<u>m</u>";
		frm.TxtDenngay.disabled=false;
		frm.TxtTungay.disabled=false;
		frm.TxtTrichyeu.disabled=false;
		frm.TxtDenngay.value="<%=Formatdate(Date())%>";
		frm.TxtTungay.value="<%=Formatdate(Date()-90)%>";
	
		frm.TxtTrichyeu.focus();
		return false;
	}
	if(trim(frm.TxtTungay.value)!=""){
		if (!isDate(frm.TxtTungay.value)){
			alert("Ngày không hợp lệ");
			frm.TxtTungay.focus();
			return false;
		}
	}
	if(trim(frm.TxtDenngay.value)!=""){	
		if (!isDate(frm.TxtDenngay.value)){
			alert("Ngày không hợp lệ");
			frm.TxtDenngay.focus();
			return false;
		}
	}
	window.frm.target="right"
	window.frm.action="frmdsxuly.asp?Chon=<%=request("chon")%>&bComm=search";
	window.frm.submit();	
}

function CmdLamtuoi_onclick() {
	window.frm.target="right"
	window.frm.action="frmdsxuly.asp";
	window.frm.submit();
}

function CmdOne_onclick() {
	  window.frm.target="right";
	  window.frm.action="frmdsxuly.asp?Chon=one";
	  window.frm.submit();
}

function CmdAll_onclick() {
	  window.frm.target="right";
	  window.frm.action="frmdsxuly.asp?Chon=all";
	  window.frm.submit();
}

function TxtTungay_onkeyup(str){
var keycode
keycode=window.event.keyCode
if (isEdit(keycode,str)){
	frm.TxtTungay.value=editdate(trim(str))
}
}

function TxtDenngay_onkeyup(str){
var keycode
keycode=window.event.keyCode
if (isEdit(keycode,str)){
	frm.TxtDenngay.value=editdate(trim(str))
}
}

function SetFocus(){
	window.frm.CmdSearch.focus();
}
//-->
</SCRIPT>

</head>
<body leftmargin=2 topmargin="2" onload="SetFocus()">
<form name=frm method=post target=right>
<Input type=hidden name="strURL" value="">
	<table bgColor="#BDD5D0" border="0" width="100%" cellspacing="0" cellpadding="0">
		<tbody>
          <tr>
            <TD BGCOLOR="#000080" COLSPAN="6" WIDTH="100%" ALIGN="CENTER"><FONT COLOR="#FFFFFF" FACE="Arial" size=2>XỬ LÝ CÔNG VIỆC</FONT></TD>
          </tr>
          <tr>
            <td width="15%" align="center">Trích yếu</td>
            <td width="70%" colspan="4"><textarea disabled name="TxtTrichyeu" style="FONT-FAMILY: Arial;width:100%" rows=1 cols=50></textarea></td>
            <td width="15%"><Button language="javascript" name="CmdLamtuoi" onclick="return CmdLamtuoi_onclick()" style="font-family: Arial; height: 25; position: relative; width:100%" accesskey="L"><p><u>L</u>àm tươi</p></Button></td>
          </tr>
          <tr>
            <td width="15%" align="center">Ngày tạo</td>
            <td width="15%" align="center">Từ ngày</td>
            <td width="20%" align="center">
            <input disabled name="TxtTungay" style="FONT-FAMILY: Arial;width:100%" maxLength=10 LANGUAGE=javascript onkeyup="return TxtTungay_onkeyup(this.value)" size="20"></td>
            <td width="15%" align="center">Ðến ngày</td>
            <td width="20%">
            <input disabled name="TxtDenngay" style="FONT-FAMILY: Arial;width:100%" maxLength=10 LANGUAGE=javascript onkeyup="return TxtDenngay_onkeyup(this.value)" size="20"></td>
            <td width="15%"><Button language="javascript" name="CmdSearch" onclick="return CmdSearch_onclick()" style="font-family: Arial; height: 25; position: relative; width: 100%" accesskey="M"><p>Tì<u>m</u> kiếm</p></Button></td>
          </tr>
        </tbody>
      </table>

		<%if request("chon")="all" then%>
		<table border="0" width="100%" cellspacing="1" cellpadding="0">
			<tr BGCOLOR="#F8F9D9">
				<TD width="100%" align=center>
					<input type="radio" ID=R2 value=2  name =one style="FONT-FAMILY: Arial; LEFT: 0px; POSITION: relative " LANGUAGE=javascript onclick="return CmdOne_onclick()"><label for=R2 accesskey="c">Danh sách <u>c</u>ông việc cần xử lý</label>
					<input type="radio" ID=R1 value=1 checked name=all style="FONT-FAMILY: Arial; LEFT: 0px; POSITION: relative " LANGUAGE=javascript onclick="return CmdAll_onclick()"><label for=R1 accesskey="a">Danh sách t<u>ấ</u>t cả các công việc</label>
				</TD>
			</tr>
		</table>
		<%else%>
		<table border="0" width="100%" cellspacing="0" cellpadding="0">
			<tr BGCOLOR="#F8F9D9">
				<TD width="100%" align=center>
					<input type="radio" ID=R2 value=2 checked name =one style="FONT-FAMILY: Arial; LEFT: 0px; POSITION: relative" LANGUAGE=javascript onclick="return CmdOne_onclick()"><label for=R2 accesskey="c">Danh sách <u>c</u>ông việc cần xử lý</label>
					<input type="radio" ID=R1 value=1  name=all style="FONT-FAMILY: Arial; LEFT: 0px; POSITION: relative " LANGUAGE=javascript onclick="return CmdAll_onclick()"><label for=R1 accesskey="a">Danh sách t<u>ấ</u>t cả các công việc</label>
				</TD>
			</tr>
		</table>
		<%end if%>

<table border="0" width="100%" style="border-style: solid;Border-color:#C0C0C0">
  <tr>
	<TD width="100%" COLSPAN="3" BGCOLOR="#000080" ALIGN=CENTER>
    <font Face="Arial" size=2 color="#FFFFFF">CÔNG VIỆC CẦN XỬ LÝ</FONT></TD>
  </tr>
  <tr bgcolor="#BDD5D0">
    <td width="5%" align="center"></td>  
    <td width="75%" align="center"><b>Chủ đề</b></td>
    <td width="20%" align="center"><b>Ngày tạo</b></td>
    <%	
	If Not Rec.Eof Then
		nRecCount = Rec.RecordCount
		Rec.PageSize = 20
		nPageCount = Rec.PageCount
		If nPage < 1 then
			nPage = 1			
		End If
		if nPage > nPageCount Then
			nPage=nPageCount
		end if
		cnt=(pg-1)*pgsize + 1		    
		STT=1
		rec.AbsolutePage=nPage
		howmanyrecs=0
		do while not Rec.EOF and howmanyrecs<rec.PageSize
			if (cnt/2=int(cnt/2)) then
				color="#eeeecc"
			else
				color="#F8F9D9"
			end if
		
    %>
  <tr id=mnu_<%=STT%> style="BORDER-RIGHT: #e7e7e7 1px solid; BORDER-TOP: #e7e7e7 1px solid; BORDER-LEFT: #e7e7e7 1px solid; COLOR: #666666; BORDER-BOTTOM: #e7e7e7 1px solid; HEIGHT: 21px; BACKGROUND-COLOR: <%=color%>" 
 onmouseover="javascript:MouseOverMenu('mnu_<%=STT%>')" onmouseout="javascript:MouseOutMenu('mnu_<%=STT%>','<%=color%>')">
		<%
			sSQL="Select username from canbo where macanbo like '"& Rec("Nguoitao") &"'"
			Set RecTemp=server.CreateObject("ADODB.Recordset")
			RecTemp.CursorType=3
			RecTemp.CacheSize=5
			RecTemp.Open sSQL,Conn
			if (not RecTemp.EOF) and (not  rectemp.BOF) then
				Nguoitao=RecTemp("username")
			end if
			RecTemp.Close
			Set RecTemp=nothing			
		%>
		<%
			sSQL="Select Trangthaixl from flownode where maworkflow Like '"& Rec("Maworkflow") &"' and nguoixuly Like '"& Session("bMaCB") &"' order by trangthaixl"
			Set RecXL=server.CreateObject("ADODB.Recordset")
			RecXL.CursorType=3
			RecXL.CacheSize=5
			RecXL.Open sSQL,Conn
			Count=RecXL.RecordCount			
			Dim Red,Blue,Brown,Grey
			Red=0
			Blue=0
			Brown=0
			Grey=0
			Do While not RecXL.EOF
				if RecXL("trangthaixl")=0 then
						Red=Red+1
				end if
				if RecXL("trangthaixl")=2 then
						Blue=Blue+1
				end if
				if RecXL("trangthaixl")=-1 then
						Grey=Grey+1
				end if
				RecXL.MoveNext
			Loop			
			if Red=Count then
				  icon="images/Thudo.gif"
				  bIcon="red"
			end if
			if Blue=Count then
				  icon="images/Thuxanh.gif"
				  bIcon="blue"
			end if
			if Grey=Count then
				  icon="images/Thuxam.gif"
				  bIcon="gray"
			end if
			if (Red<>count) and (Blue<>count) and (Grey<>count) then
				  icon="images/Thuvang.gif"
				  bIcon="brown"
			end if
			
		%>
		<td width="5%" align=center><a style='text-decoration: none' href="xulyflow.asp?bMaRoot=<%=Rec("Nguoitao")%>&IDFlow=<%=Rec("Maworkflow")%>&Nguoitao=<%=Session("bMaCB")%>&bicon=<%=bicon%>" target=right><Img src=<%=icon%> border=0></a></td>
		<td width="75%"><a style='text-decoration: none' href="xulyflow.asp?bMaRoot=<%=Rec("Nguoitao")%>&IDFlow=<%=Rec("Maworkflow")%>&Nguoitao=<%=Session("bMaCB")%>&bicon=<%=bicon%>" target=right><%=Rec("Tenvuviec")%></a></td>
		<td width="20%" align=center><a style='text-decoration: none' href="xulyflow.asp?bMaRoot=<%=Rec("Nguoitao")%>&IDFlow=<%=Rec("Maworkflow")%>&Nguoitao=<%=Session("bMaCB")%>&bicon=<%=bicon%>" target=right><%=formatdate(Rec("Ngaytao"))%></a></td>
  </tr>
  <input type="hidden" name="ID<%=STT%>" value="<%=Rec("Maworkflow")%>">
	<%
		if  Session("VanBan")="" then
			Session("VanBan")="-" & Rec("Maworkflow") 
		else
			Session("VanBan")=Session("VanBan") & "-" & Rec("Maworkflow") 
		end if
	%>
  <%		STT=STT+1
			Rec.MoveNext
			cnt=cnt+1
			howmanyrecs=howmanyrecs+1
		loop
		Session("VanBan")=Session("VanBan") & "-"
	end if
	rec.Close
	set rec=nothing
  %>
</table>
 <!-- Phan trang -->
<br>
<table width="98%" cellspacing=0 cellpadding=0>
<tr>
<% if nPage > 0 and nPageCount >0  then %>  
	<td width="20%"><b>Trang&nbsp; <%=nPage%>/<%=nPageCount%></b></td>
<!-- 	<td width= "80%" align="right">
	<% if nPageCount > 1 then %>    
		Chuyển nhanh tới trang:&nbsp;
		<select name="page" style="width:45;height:23;font-size:8pt" size=1 onchange="javaScript:ChangePage()">
			<% for i = 1 to nPageCount%>	
				<% if bComm<>"search"  then
					strURL="frmDsXuly.asp?Chon="& Chon &"&bsearch="& bsearch &"&Loaitim="& loaitim &"&page="+ cstr(i) + "&bComm="
				else
					strURL="frmDsXuly.asp?Chon="& Chon &"&bsearch="& bsearch &"&Loaitim="& loaitim &"&page="+ cstr(i) + "&bComm=search"
				end if %>
				<option value="<%=strURL%>" <%=chkSelected(i, nPage)%>><%=i%></option>
			<% next %>    
		</select>
		</td>                                  
	<% end if %>      -->        
<% 'else %>
<% end if %>
<td width= "80%" align="center"><%=Paging(nPage, nPageCount, nRecCount)%></td>
  </tr>
</table>
</body>
</form>
</html>
<%
	Conn.Close
	Set Conn=nothing
%>